package com.suge.send.tcp;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.jasson.mas.api.sms.SmsApiClientHandler;
import com.jasson.mas.api.smsapi.Report;
import com.jasson.mas.api.smsapi.Sms;
import com.suge.order.dao.dataobject.SmsOrderDO;
import com.suge.order.manager.SmsOrderManager;

public class SmsApiClientHandlerImpl implements SmsApiClientHandler{

	private static final Logger logger = LoggerFactory.getLogger(SmsApiClientHandlerImpl.class);

	private SmsOrderManager smsOrderManager;
	
	private SmsOrderDO orderDO;
	
	SmsApiClientHandlerImpl(SmsOrderDO orderDO,SmsOrderManager smsOrderManager){
		this.setOrderDO(orderDO);
		this.setSmsOrderManager(smsOrderManager);
	}
	
	public void notifySmsReception(Sms sms) {
		logger.error("sms notify ********" + sms. destID + "||"+ sms.content +"||" + sms. mobile);
	}
	
	public void notifySmsDeliveryStatus(String submitID, Report[] report) { 
		logger.error("notifySmsDeliveryStatus"+ report.length +": SmsReport submitID: " + submitID + " sendResul= " + report [0].sendResult);
		logger.error("this order id is:"+this.getOrderDO().getOrderId());
		
		this.getOrderDO().setReportLength( String.valueOf(report.length));
		this.getOrderDO().setSubmitId(submitID);
		this.getOrderDO().setSendFinishTime(new Date());
		logger.error("this order submint id  is:"+this.getOrderDO().getSubmitId());
		this.getSmsOrderManager().updateSmsOrderInfo(this.getOrderDO());
	}

	public void setSmsOrderManager(SmsOrderManager smsOrderManager) {
		this.smsOrderManager = smsOrderManager;
	}

	public SmsOrderManager getSmsOrderManager() {
		return smsOrderManager;
	}

	public void setOrderDO(SmsOrderDO orderDO) {
		this.orderDO = orderDO;
	}

	public SmsOrderDO getOrderDO() {
		return orderDO;
	}

}
